package com.study.core.aop;

import com.study.core.annotation.AopMethod;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @Description TODO
 * @Author v_yangliu
 * @Date 2022/1/11 17:45
 * @Version 1.0
 **/
@Component
@Aspect
@Slf4j
public class SpringAspect {

    @Pointcut("@annotation(com.study.core.annotation.AopMethod)")
    public void cut(){

    }

    @Around("cut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        MethodSignature signature= (MethodSignature) point.getSignature();
        Method method= signature.getMethod();
        AopMethod annotation= method.getAnnotation(AopMethod.class);
        log.info("切面获取的注解名称为:{}",annotation.name());
        return point.proceed();
    }
}
